<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>管理员管理</title>
<link rel="stylesheet" href="/layui/css/layui.css">
<script src="/static/js/jquery.min.js"></script>
<script src="/layui/layui.js"></script>
<style>body{background:#f5f5f5;padding:20px;}</style>
</head>
<body>
<div class="layui-card"><div class="layui-card-header">管理员列表 <button class="layui-btn layui-btn-sm layui-btn-normal" style="float:right;" onclick="addAdmin()">添加管理员</button></div>
<div class="layui-card-body"><table class="layui-table" lay-size="sm"><thead><tr><th>ID</th><th>账号</th><th>昵称</th><th>手机号</th><th>邮箱</th><th>角色</th><th>状态</th><th>登录时间</th><th>操作</th></tr></thead>
<tbody><?php foreach($list as $admin): ?><tr><td><?= $admin['id'] ?></td><td><?= $admin['username'] ?></td><td><?= $admin['nickname'] ?></td><td><?= $admin['phone'] ?></td><td><?= $admin['email'] ?></td><td><?= $admin['role'] ?></td><td><?= $admin['status']?'<span style="color:green">正常</span>':'<span style="color:red">禁用</span>' ?></td><td><?= $admin['login_time'] ?? '-' ?></td><td><button class="layui-btn layui-btn-xs layui-btn-normal" onclick="editAdmin(<?= $admin['id'] ?>)">编辑</button><?php if($admin['id']!=$adminId): ?> <button class="layui-btn layui-btn-xs layui-btn-danger" onclick="deleteAdmin(<?= $admin['id'] ?>)">删除</button><?php endif; ?></td></tr><?php endforeach; ?></tbody></table></div></div>
<div id="adminModal" style="display:none;padding:20px;"><form class="layui-form" lay-filter="adminForm"><input type="hidden" name="id" value="0"><div class="layui-form-item"><label class="layui-form-label">账号</label><div class="layui-input-block"><input type="text" name="username" lay-verify="required" class="layui-input"></div></div><div class="layui-form-item"><label class="layui-form-label">密码</label><div class="layui-input-block"><input type="password" name="password" placeholder="留空则不修改" class="layui-input"></div></div><div class="layui-form-item"><label class="layui-form-label">昵称</label><div class="layui-input-block"><input type="text" name="nickname" class="layui-input"></div></div><div class="layui-form-item"><label class="layui-form-label">手机号</label><div class="layui-input-block"><input type="text" name="phone" lay-verify="required" class="layui-input"></div></div><div class="layui-form-item"><label class="layui-form-label">邮箱</label><div class="layui-input-block"><input type="text" name="email" lay-verify="required|email" class="layui-input"></div></div><div class="layui-form-item"><label class="layui-form-label">角色</label><div class="layui-input-block"><select name="role"><option value="admin">管理员</option><option value="super">超级管理员</option></select></div></div></form></div>
<script>
var adminList=<?= json_encode($list,JSON_UNESCAPED_UNICODE) ?>;
layui.use(['form','layer'],function(){var f=layui.form;
addAdmin=function(){$('#adminModal [name="id"]').val(0);$('#adminModal [name="username"]').val('').removeAttr('readonly');$('#adminModal [name="password"]').attr('placeholder','请输入密码').attr('lay-verify','required');$('#adminModal [name="nickname"]').val('');$('#adminModal [name="phone"]').val('');$('#adminModal [name="email"]').val('');f.render();layer.open({type:1,title:'添加管理员',area:['500px','420px'],content:$('#adminModal'),btn:['确定','取消'],yes:function(index){var d={};$('#adminModal [name]').each(function(){d[$(this).attr('name')]=$(this).val();});$.post('/admin/system/adminAdd',d,function(res){layer.msg(res.msg,{icon:res.code===0?1:2});if(res.code===0) setTimeout(function(){location.reload();},1000);});}});};
editAdmin=function(id){var a=adminList.find(function(a){return a.id==id;});if(!a)return;$('#adminModal [name="id"]').val(a.id);$('#adminModal [name="username"]').val(a.username).attr('readonly','readonly');$('#adminModal [name="password"]').val('').attr('placeholder','留空则不修改密码').removeAttr('lay-verify');$('#adminModal [name="nickname"]').val(a.nickname);$('#adminModal [name="phone"]').val(a.phone);$('#adminModal [name="email"]').val(a.email);$('#adminModal [name="role"]').val(a.role);f.render();layer.open({type:1,title:'编辑管理员',area:['500px','420px'],content:$('#adminModal'),btn:['确定','取消'],yes:function(index){var d={};$('#adminModal [name]').each(function(){d[$(this).attr('name')]=$(this).val();});$.post('/admin/system/adminEdit',d,function(res){layer.msg(res.msg,{icon:res.code===0?1:2});if(res.code===0) setTimeout(function(){location.reload();},1000);});}});};
deleteAdmin=function(id){layer.confirm('确认删除该管理员？',function(){$.post('/admin/system/adminDelete',{id:id},function(res){layer.msg(res.msg,{icon:res.code===0?1:2});if(res.code===0) setTimeout(function(){location.reload();},1000);});});};
});
</script>
</body>
</html>